package org.vgou.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * 
 * Copyright (c) 2011, vgou All rights reserved.
 * 
 * @since Nov 27, 2011
 * @author <a href="mailto:jason.hxx@gmail.com">jason</a>
 * @version Id: Product.java Nov 27, 2011
 * @comment 产品实体类
 * 
 */
@Entity
// 更新一个对象时,会生成动态SQL,当属性值发生变化时，才会包含到UPDATE语句中
@org.hibernate.annotations.Entity(dynamicUpdate = true, dynamicInsert = true)
@Table(name = "product")
public class Product implements Serializable {

	private static final long serialVersionUID = -1726082215467744456L;

	/** 编号 **/
	@Id
	@GeneratedValue
	@Column(name="id", length=19)
	private long id;
	
	/** 产品主题  **/
	@Column(name="title", nullable=false)
	private String title;
	
	/** 状态  1 未审核  2 已审核 3 屏蔽  4 团购成功 5团购失败 **/
	@Column(name="status", length=10, nullable=false)
	private int status = 1;
	
	/** 产品快照 **/
	@Lob
	@Column(name="snapshot", nullable=false)
	private byte[] snapshot;
	
	/** 原价 **/
	@Column(name="originalcost", nullable=false)
	private float originalcost = 0;
	
	/** 现价 **/
	@Column(name="currentprice", nullable=false)
	private float currentprice = 0;
	
	/** 发布时间 **/
	@Column(name="pubtime",nullable=false)
	private Date pubTime = new Date();
	
	/** 开始时间 **/
	@Column(name="starttime",nullable=false)
	private Date startTime = new Date();
	
	/** 最少团购人数 **/
	@Column(name="minimum", nullable=false)
	private int minimum = 0;
	
	/** 达标时间 **/
	@Column(name="standardtime",nullable=false)
	private Date standardTime = new Date();
	
	/** 短语点评 **/
	@Column(name="summary")
	private String summary;
	
	/** 温馨提示 **/
	@Column(name="tips")
	private String tips;
	
	/** 产品类型 **/
	@ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
	@JoinColumn(name="businessid")
	private Business business;

	/** 产品条目 **/
	@OneToMany(mappedBy="product", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
	private Set<ProductItem> items = new HashSet<ProductItem>();
	
	/** 产品订单 **/
	@OneToMany(mappedBy="product", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
	private Set<Order> orders = new HashSet<Order>();
	
	public Product() {
		super();
	}

	public Product(long id, String title, int status, byte[] snapshot,
			float originalcost, float currentprice, Date pubTime,
			Date startTime, int minimum, Date standardTime, String summary,
			String tips, Business business) {
		super();
		this.id = id;
		this.title = title;
		this.status = status;
		this.snapshot = snapshot;
		this.originalcost = originalcost;
		this.currentprice = currentprice;
		this.pubTime = pubTime;
		this.startTime = startTime;
		this.minimum = minimum;
		this.standardTime = standardTime;
		this.summary = summary;
		this.tips = tips;
		this.business = business;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public byte[] getSnapshot() {
		return snapshot;
	}

	public void setSnapshot(byte[] snapshot) {
		this.snapshot = snapshot;
	}

	public float getOriginalcost() {
		return originalcost;
	}

	public void setOriginalcost(float originalcost) {
		this.originalcost = originalcost;
	}

	public float getCurrentprice() {
		return currentprice;
	}

	public void setCurrentprice(float currentprice) {
		this.currentprice = currentprice;
	}

	public Date getPubTime() {
		return pubTime;
	}

	public void setPubTime(Date pubTime) {
		this.pubTime = pubTime;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public int getMinimum() {
		return minimum;
	}

	public void setMinimum(int minimum) {
		this.minimum = minimum;
	}

	public Date getStandardTime() {
		return standardTime;
	}

	public void setStandardTime(Date standardTime) {
		this.standardTime = standardTime;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getTips() {
		return tips;
	}

	public void setTips(String tips) {
		this.tips = tips;
	}

	public Business getBusiness() {
		return business;
	}

	public void setBusiness(Business business) {
		this.business = business;
	}

	public Set<ProductItem> getItems() {
		return items;
	}

	public void setItems(Set<ProductItem> items) {
		this.items = items;
	}

	public Set<Order> getOrders() {
		return orders;
	}

	public void setOrders(Set<Order> orders) {
		this.orders = orders;
	}
	
}
